/*
 * Game - container of the current game's state (in terms of functionality)
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */


class Game
{

	public var map : Array<Array<GameTile>>;

	public var curinput : Dynamic;

	public var fortadditions : Array<FortressData>;
	public var fortremovals : Array<FortressData>;

	public var creepman : CreepManager;
	public var shooterman : ShooterManager;
	public var fight : Fight;
	
	public var score : Int;
	public var gamemode : Int;
	public var phase : Int; // phase of gameplay

	public static var cur : Game;

	public function new(gamemode : Int)
	{
		// initialize the game
		// this is strictly gameplay elements and the "controller"
		
		score = 0;
		this.gamemode = gamemode;
		phase = 1;

		creepman = new CreepManager();
		shooterman = new ShooterManager();
		fortadditions = new Array();
		fortremovals = new Array();
		fight = new Fight();

		map = Graph.init(26,26);
		
	}
	
	public function control()
	{
		switch(cur.phase)
		{
			case(-1): // no game
			case(0): // game over
			case(1): // game continues, start placement
				fortadditions = new Array();
				fortremovals = new Array();
			case(2): // during placement
			case(3): // placement over
				{
					// do stuff with curinput
					Fight.start();
					cur.phase = 4;
				}
			case(4): // fight
				var result = HLInput.runFight();
				
				switch(result)
				{
					case(-1): // loss
						cur.phase = 0;
						Fight.end();
					case(0): // continue
					case(1): // wave over
						cur.phase = 1;
						Fight.end();
				}
			case(5): // start game
		}		
	}
	
}
